package com.lg.winclient;

import lombok.extern.slf4j.Slf4j;

import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;

@Slf4j
public class SendThread extends Thread {

    private String msg;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    private Socket socket;

    public Socket getSocket() {
        return socket;
    }

    public void setSocket(Socket socket) {
        this.socket = socket;
    }

    public SendThread(Socket socket) {
        this.socket = socket;
    }

    public SendThread(Socket socket, String msg) {
        this.socket = socket;
        this.msg = msg;
    }

    public SendThread() {
        log.info("构造函数SendThread");
    }

    public void run() {
        DataOutputStream dataOutputStream;
        try {
            dataOutputStream = new DataOutputStream(socket.getOutputStream());
            while (true) {
                if (msg != null) {
                    log.info("消息发送中:{}", msg);
                    dataOutputStream.writeUTF(msg);
                    msg = null;
                }
                Thread.sleep(50);
            }

        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


    }

}
